# -*- coding=utf8 -*-
__author__ = 'cosven'

import os

from flask.ext.assets import Bundle

from blog import assets

"""
配置assets
1. css的预编译
2. css和js的压缩
"""
assets.manifest = 'cache'
# only work for python2.7
# lessc_path = subprocess.check_output("which lessc; exit 0",
#                                      stderr=subprocess.STDOUT, shell=True)
# assets.config['less_bin'] = lessc_path[:-1]
# print 'fuck', lessc_path[:-1]
debug = os.environ.get("FLASK_DEBUG")
if debug is not None:   # debug mode, in my own computer
    assets.config['less_bin'] = '/home/ysw/.nvm/v0.10.33/bin/lessc'
else:
    assets.config['less_bin'] = '/usr/local/bin/lessc'

js_test = Bundle('js/test.js', filters='jsmin', output='public/test.min.js')
js_login = Bundle('js/jquery.min.js', 'js/login.js',
                  filters='jsmin', output='public/login.min.js')
# admin的ace editor有些问题，所以
js_admin_all = Bundle(
    Bundle(
        'js/jquery.min.js',
        output='public/admin_base.min.js'
    ),
    Bundle(
        'js/ace/ace.js',
        'js/noty/packaged/jquery.noty.packaged.js'
    ),
    Bundle(
        'js/common.js',
        'js/admin.js',
        filters='jsmin',
        output='public/admin_all.min.js'
    )
)

js_normal_all = Bundle(
    Bundle(
        'js/jquery.min.js',
        'js/marked.min.js',
        'js/highlight.min.js',
    ),
    Bundle(
        'js/noty/packaged/jquery.noty.packaged.min.js'
    ),
    Bundle(
        'js/common.js',
        'js/base.js',
        filters='jsmin',
        output='public/normal_all.min.js'
    )
)

less_home = Bundle('less/home.less', filters='less, cssmin',
                   output='public/home.min.css')
less_base = Bundle('less/base.less',
                   'less/site.less',
                   filters='less, cssmin',
                   output='public/base.min.css')
less_blog = Bundle(
    Bundle('css/highlight.min.css',
           ),
    Bundle('css/markdown-gt.css',
           filters='cssmin',
           output='public/markdown-gt.min.css'
           ),
    Bundle('less/blog.less',
           filters='less, cssmin',
           output='public/blog.min.css')
)
less_login = Bundle('less/login.less',
                    'less/site.less',
                    filters='less, cssmin',
                    output='public/login.min.css')
less_admin = Bundle('less/admin.less',
                    'less/site.less',
                    filters='less, cssmin',
                    output='public/admin.min.css')
less_index = Bundle('less/index.less',
                    filters='less, cssmin',
                    output='public/index.min.css')


assets.register('js_test', js_test)
assets.register('js_login', js_login)
assets.register('js_admin_all', js_admin_all)
assets.register('js_normal_all', js_normal_all)
assets.register('css_base', less_base)
assets.register('css_home', less_home)
assets.register('css_blog', less_blog)
assets.register('css_login', less_login)
assets.register('css_admin', less_admin)
assets.register('css_index', less_index)
